package demo6;


/**
 * 二叉树的深搜_计算布尔二叉树的值
 * https://leetcode.cn/problems/evaluate-boolean-binary-tree/
 */
class Solution {
    public boolean evaluateTree(TreeNode root) {
        // 出口
        if(root.left == null) return root.val == 1 ? true : false;
        boolean left = evaluateTree(root.left);
        boolean right = evaluateTree(root.right);

        return root.val == 2 ?  left | right : left & right;
    }
}